/*
 * Copyright (c) International Business Machines
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

const mappingarray = [
  0.1442960141, 0.2883290589, 0.4394455009, 0.6251033551, 0.8494680628,
  1.114269342, 1.421009327, 1.77098291, 2.165293347, 2.60486502, 3.090454395,
  3.622659702, 4.201929527, 4.828570276, 5.502752403, 6.22451526, 6.993770447,
  7.810303633, 8.67377486, 9.583717449, 10.53953568, 11.54050149, 12.58575041,
  13.67427713, 14.80493088, 15.97641099, 17.18726271, 18.43587366, 19.72047078,
  21.03911807, 22.38971501, 23.76999574, 25.17752929, 26.60972094, 28.06381532,
  29.53690169, 31.02592249, 32.52768571, 34.03888232, 35.55610935, 37.07589918,
  38.59475509, 40.10919254, 41.61578505, 43.11121294, 44.59231265, 46.05612431,
  47.49993483, 48.9213144, 50.31814442, 51.68863577, 53.031337, 54.34513247,
  55.62923153, 56.88315004, 58.10668568, 59.29988909, 60.46303237, 61.59657658,
  62.70113959, 63.56326058, 64.41202953, 65.24664967, 66.06640516, 66.87066232,
  67.65886935, 68.43055486, 69.18532512, 69.92286041, 70.64291052, 71.3452897,
  72.02987117, 72.69658137, 73.34539418, 73.9763252, 74.58942614, 75.18477959,
  75.76249404, 76.32269938, 76.8655428, 77.39118511, 77.8997976, 78.39155929,
  78.8666546, 79.32527148, 79.76759988, 80.1938306, 80.60415443, 80.99876155,
  81.37784127, 81.74158189, 82.09017079, 82.42379468, 82.74263998, 83.04689331,
  83.3367421, 83.6123752, 83.87398367, 84.12176148, 84.35590639, 84.57662074,
  84.78411234, 84.97859538, 85.16029134, 85.32942996, 85.48625022, 85.63100145,
  85.76394437, 85.88535238, 85.99551287, 86.09472877, 86.18332024, 86.26162681,
  86.33000985, 86.3888557, 86.43857968, 86.47963142, 86.51298283, 86.54471868,
  86.57646146, 86.64555598, 86.71430023, 86.78618922, 86.87418665, 86.98006623,
  87.10439456, 87.24758613, 87.40991801, 87.59154385, 87.79250821, 88.012761,
  88.25217223, 88.51054674, 88.78763869, 89.08316553, 89.39682122, 89.72828858,
  90.07725044, 90.44339981, 90.82644883, 91.22613659, 91.642236, 92.07455966,
  92.52296494, 92.98735837, 93.46769955, 93.96400453, 94.47634902, 95.00487136,
  95.54977543, 96.11133365, 96.68988998, 97.28586313, 97.89974993, 98.53212885,
  99.18366357, 99.85510661, 100.5473027, 101.2611914, 101.9978094, 102.7582903,
  103.5438626, 104.3558441, 105.1956307, 106.0646795, 106.9644813, 107.8965228,
  108.8622337, 109.8629169, 110.899659, 111.9732204, 113.0839069, 114.2314258,
  115.4147382, 116.6319205, 117.8800573, 119.1551886, 120.4523352, 121.7656213,
  123.0884986, 124.6661865, 126.270493, 127.8955983, 129.5355182, 131.1845976,
  132.8380102, 134.4921811, 136.1450473, 137.7960723, 139.4459543, 141.096004,
  142.7472533, 144.3994757, 146.0504219, 147.6956209, 149.328993, 150.9442359,
  152.536562, 154.1041013, 155.6483704, 157.1736636, 158.6857597, 160.1905717,
  161.6932066, 163.1975483, 164.7062217, 166.2207254, 167.741585, 169.2684565,
  170.8001538, 172.3345565, 173.8683018, 175.3961851, 176.9105991, 178.4020807,
  179.8614412, 181.2816817, 182.6581648, 183.9878067, 185.2683416, 186.4979104,
  187.674871, 188.7977175, 189.8650475, 190.8755529, 191.8280209, 192.7213456,
  193.554545, 194.326786, 195.0374147, 195.6859926, 196.2723371, 196.7965646,
  197.2591373, 197.6609093, 198.0031759, 198.2877235, 198.5202466, 198.7426554,
  198.9662576, 199.0282765, 199.0901946, 199.155171, 199.2350179, 199.3315391,
  199.4454944, 199.5775492, 199.7282831, 199.8981955, 200.0877113, 200.2971837,
  200.5268984, 200.7770763, 201.0478759, 201.3393965, 201.651681, 201.9847185,
  202.3384476, 202.7127591, 203.1075, 203.5224761, 203.9574561, 204.4121754,
  204.8863393, 205.3796278, 205.8916987, 206.4221921, 206.9707346, 207.5369425,
  208.1204267, 208.7207956, 209.3376588, 209.9706306, 210.6193313, 211.2833894,
  211.96244, 212.6561215, 213.3640661, 214.0858827, 214.8211272, 215.5692536,
  216.3295449, 217.1010253, 217.882378, 218.6719157, 219.4676565, 220.2675148,
  221.0695361, 221.8720737, 222.6738503, 223.4739266, 224.2716256, 225.0664573,
  225.8580571, 226.6461442, 227.4304939, 228.2109205, 228.9872671, 229.7593987,
  230.5271985, 231.0766435, 231.6335656, 232.1981862, 232.7707353, 233.3514526,
  233.9405891, 234.5384081, 235.1451868, 235.7612184, 236.3868134, 237.0223022,
  237.6680372, 238.3243949, 238.9917779, 239.6706172, 240.3613737, 241.0645391,
  241.780636, 242.5102172, 243.2538627, 244.0121759, 244.7857762, 245.5752903,
  246.3813393, 247.2045232, 248.045402, 248.9044727, 249.7821441, 250.6787071,
  251.5943065, 252.5289064, 253.4822596, 254.453877, 255.4429991, 256.4485727,
  257.4692316, 258.5032837, 259.5487048, 260.6031384, 261.6639011, 262.7279922,
  263.7921059, 264.8526438, 265.9057254, 266.9471941, 267.9726181, 268.977285,
  269.9561907, 270.9040263, 271.8151684, 272.6836823, 273.5033512, 274.2677506,
  274.9703869, 275.6049239, 276.165512, 276.6472244, 277.0525184, 277.4509263,
  277.8630485, 278.0073445,
];

export const uniqueColor = (index: number, numberOfColors: number) => {
  const baseHue = mappingarray[196];

  const endHue = mappingarray[mappingarray.length - 1];
  const goal = ((index * endHue) / numberOfColors + baseHue) % endHue;
  const closest = mappingarray.reduce((prev, curr) => {
    return Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev;
  });

  const hue = mappingarray.indexOf(closest);
  return `hsl(${hue}, 100%, 50%)`;
};
